package com.ctshk.rpc.custom.mapper;

import com.ctshk.rpc.custom.dto.quotation.CollectionTouristFeeDTO;
import com.ctshk.rpc.custom.dto.quotation.SubtotalDTO;
import com.ctshk.rpc.custom.entity.CustomizedQuotationCollectionTouristFee;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 代收费用旅客类型价格 Mapper 接口
 * </p>
 *
 * @author 谢诗宏
 * @since 2021-01-16
 */
public interface CustomizedQuotationCollectionTouristFeeMapper extends BaseMapper<CustomizedQuotationCollectionTouristFee> {

    /**
     * 代收费用明细列表
     * @param collectionId
     * @return
     */
    @Select("SELECT a.tourist_type_id,a.tourist_type_name,a.total_amount AS price,b.people_num AS number,(a.total_amount * b.people_num) AS totalAmount,a.currency_id,a.currency,a.exchange_rate \n" +
            "FROM t_customized_quotation_collection_tourist_fee a \n" +
            "LEFT JOIN (SELECT * FROM t_customized_quotation_tourist_type WHERE quotation_id = #{quotation_id} GROUP BY main_data_id) b ON a.tourist_type_id = b.main_data_id\n" +
            "LEFT JOIN t_customized_quotation_collection_fee c ON a.collection_id = c.id\n" +
            "WHERE a.collection_id = #{collection_id} AND c.is_deleted = 0 ORDER BY b.sort")
    List<CollectionTouristFeeDTO> queryCollectionTouristFeeDetailList(@Param("collection_id")Long collectionId,@Param("quotation_id")Long quotationId);

    /**
     * 小计
     * @param quotationId
     * @return
     */
    @Select("SELECT tourist_type_id AS mainDataId,SUM(total_amount) AS amount\n" +
            "FROM t_customized_quotation_collection_tourist_fee\n" +
            "WHERE quotation_id = #{quotation_id}\n" +
            "GROUP BY tourist_type_id")
    List<SubtotalDTO> sumAmountByTouristType(@Param("quotation_id")Long quotationId);
}
